package freshmanspecial.mredrock.com.welcomefreshman.Adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import freshmanspecial.mredrock.com.welcomefreshman.Bean.ExcellentStuBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.ExcellentTechBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.MilitaryTrainingPhotoBean;
import freshmanspecial.mredrock.com.welcomefreshman.R;
import freshmanspecial.mredrock.com.welcomefreshman.Util.CustomDialog;

/**
 * Created by HP on 2017/8/12.
 */
public class GoodPeopleAdapter extends RecyclerView.Adapter<GoodPeopleAdapter.MyGoodPeopleHoler>{
    private MilitaryTrainingPhotoBean bean;
    private Context context;
    private int type,student=1,teacher=2;
    private ExcellentStuBean stuBean;
    private ExcellentTechBean techBean;
    public GoodPeopleAdapter(Object object, Context context,int type){
        if(type==student)
        {
            stuBean = (ExcellentStuBean) object;
        }else {
            techBean = (ExcellentTechBean) object;
        }
        this.context = context;
        this.type = type;
    }
    @Override
    public MyGoodPeopleHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        if(type==student)
        {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.special_2017_mien_student_recycler_item,parent,false);
            GoodPeopleAdapter.MyGoodPeopleHoler myGoodPeopleHoler = new GoodPeopleAdapter.MyGoodPeopleHoler(view);
            return myGoodPeopleHoler;
        }else {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.special_2017_mien_teacher_recycler_item,parent,false);
            GoodPeopleAdapter.MyGoodPeopleHoler myGoodPeopleHoler = new GoodPeopleAdapter.MyGoodPeopleHoler(view);
            return myGoodPeopleHoler;
        }
    }

    @Override
    public void onBindViewHolder(MyGoodPeopleHoler holder, final int position) {
        if(type==student)
        {
            holder.stu_banjiang.setText(stuBean.getData().get(position).getMotto());
            holder.stu_name.setText(stuBean.getData().get(position).getName());
            Glide.with(context).load(stuBean.getData().get(position).getUrl()).into(holder.stu_imageView);


            holder.stu_button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    CustomDialog.Builder builder = new CustomDialog.Builder(context);
                    builder.setUrl(stuBean.getData().get(position).getUrl());
                    builder.setTitle(stuBean.getData().get(position).getName());
                    builder.setMessage(stuBean.getData().get(position).getResume());
                    builder.setNegativeButton(new android.content.DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                                    dialogInterface.dismiss();
                        }
                    });
                    builder.create().show();
                }
            });
        }else {
            holder.tea_text.setText(techBean.getData().get(position).getName());
            Glide.with(context).load(techBean.getData().get(position).getUrl()).into(holder.tea_imageView);

        }

    }

    @Override
    public int getItemCount() {
        if (type==1)
        {
            return stuBean.getData().size();
        }else {
            return techBean.getData().size();
        }
    }

    class MyGoodPeopleHoler extends RecyclerView.ViewHolder{
        ImageView stu_imageView,tea_imageView;
        TextView stu_name,tea_text,stu_banjiang;
        ImageButton stu_button;
        public MyGoodPeopleHoler(View itemView) {
            super(itemView);
            stu_banjiang = itemView.findViewById(R.id.student_banjiang);
            stu_imageView = itemView.findViewById(R.id.circleImageView);
            stu_name = itemView.findViewById(R.id.student_name);
            stu_button = itemView.findViewById(R.id.student_button);
            tea_imageView = itemView.findViewById(R.id.teacher_img);
            tea_text = itemView.findViewById(R.id.teacher_text);
        }
    }
}
